<?php
namespace Frieza\Modules\Ifttt\Actions;

use Doraemon\service\Ifttt as sIfttt;
use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;

class Check extends RowAction
{
    public $name = '提交审批';

    public function dialog()
    {
        $this->confirm('确定要提交审批当前任务么？');
    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function handle($id)
    {
        $result = sIfttt::submitTaskCheck($id);
        if ($result){
            return $this->response()->success('提交成功')->refresh();
        } else {
            return $this->response()->error('提交失败,请稍后重试');
        }
    }
}